package org.mspring.platform.dao.query.criterion;

/**
 * @author Gao Youbo
 * @since Jan 31, 2012
 */
public class Expression {

    /**
     * Group expressions together in a single conjunction (A and B and C...)
     *
     * @return
     */
    public static Conjunction conjunction() {
        return new Conjunction();
    }

    /**
     * Group expressions together in a single disjunction (A or B or C...)
     *
     * @return Disjunction
     */
    public static Disjunction disjunction() {
        return new Disjunction();
    }

    public static Criterion and(Criterion lhs, Criterion rhs) {
        return new LogicalExpression(lhs, rhs, "and");
    }

    public static Criterion or(Criterion lhs, Criterion rhs) {
        return new LogicalExpression(lhs, rhs, "or");
    }

    public static Criterion between(String hqlName, String beginParamKey, String endParamKey, Class<?> convertClass) {
        return new BetweenExpression(hqlName, beginParamKey, endParamKey, convertClass);
    }

    public static Criterion valuedBetween(String hqlName, Object beginParamValue, Object endParamValue) {
        return new BetweenExpression(hqlName, beginParamValue, endParamValue);
    }

    public static Criterion equal(String hqlName, String paramKey, Class<?> paramClass) {
        return new SimpleExpression(hqlName, paramKey, "=", paramClass);
    }

    public static Criterion valuedEqual(String hqlName, Object paramValue) {
        return new SimpleExpression(hqlName, paramValue, "=");
    }

    public static Criterion notEqual(String hqlName, String paramKey, Class<?> paramClass) {
        return new SimpleExpression(hqlName, paramKey, "<>", paramClass);
    }

    public static Criterion valuedNotEqual(String hqlName, Object paramValue) {
        return new SimpleExpression(hqlName, paramValue, "<>");
    }

    public static Criterion ge(String hqlName, String paramKey, Class<?> paramClass) {
        return new SimpleExpression(hqlName, paramKey, ">=", paramClass);
    }

    public static Criterion valuedGe(String hqlName, Object paramValue) {
        return new SimpleExpression(hqlName, paramValue, ">=");
    }

    public static Criterion gt(String hqlName, String paramKey, Class<?> paramClass) {
        return new SimpleExpression(hqlName, paramKey, ">", paramClass);
    }

    public static Criterion valuedGt(String hqlName, Object paramValue) {
        return new SimpleExpression(hqlName, paramValue, ">");
    }

    public static Criterion le(String hqlName, String paramKey, Class<?> paramClass) {
        return new SimpleExpression(hqlName, paramKey, "<=", paramClass);
    }

    public static Criterion valuedLe(String hqlName, Object paramValue) {
        return new SimpleExpression(hqlName, paramValue, "<=");
    }

    public static Criterion lt(String hqlName, String paramKey, Class<?> paramClass) {
        return new SimpleExpression(hqlName, paramKey, "<", paramClass);
    }

    public static Criterion valuedLt(String hqlName, Object paramValue) {
        return new SimpleExpression(hqlName, paramValue, "<");
    }

    public static Criterion in(String hqlName, String paramKey, Class<?> paramClass) {
        return new InExpression(hqlName, paramKey, paramClass);
    }

    public static Criterion like(String hqlName, String paramKey, MatchMode matchMode, Class<?> paramClass) {
        return new LikeExpression(hqlName, paramKey, " like ", matchMode, paramClass);
    }

    public static Criterion valuedLike(String hqlName, Object paramValue, MatchMode matchMode) {
        return new LikeExpression(hqlName, paramValue, " like ", matchMode);
    }

    public static Criterion notNull(String hqlName) {
        return new NotNullExpression(hqlName);
    }

    public static Criterion isNull(String hqlName) {
        return new NullExpression(hqlName);
    }
}
